package com.testwhile;

import java.util.Scanner;

public class NpStopWhile {
    static volatile String msg=null;
    static boolean flag=false;
    static {
        //输入信息线程
        Scanner scanner=new Scanner(System.in);
        new Thread(() -> {
            while (true){
                System.out.println("请输入数据测试");
                msg = scanner.nextLine();
            }
        }).start();
    }
    public static void main(String[] args) {
        System.out.println("开始");
        while (true){
            if (flag){
                System.out.println("结束循环了");
                flag=false;
                break;
            }
            while (true){
                if (msg!=null){
                    flag=true;
                    System.out.println("msg有数据了");
                    break;
                }
            }
        }
    }

}
